<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            padding: 50px;
        }

        span {
            display: inline-block;
            width: 100px;
            height: 45px;
            background-color: #64b448;
            line-height: 45px;
            color: white;
            text-align: center;
        }

        .active {
            background-color: #e35885;
        }
    </style>
</head>

<body>
    <div id="box">
        <span v-for='(val,index) in arr' @click=active(index) :class="{active:val.item}"> {{val.name}}</span>
        <p>你选择了 : <span v-for='(val,index) in arr' v-if=val.item>{{val.name}}</span></p>
    </div>
    <script src="js/vue.js"></script>
    <script>
        let vm = new Vue({
            el: "#box",
            data: {
                // 数组对象
                arr: [
                    { name: "HTML", item: true },
                    { name: "CSS", item: false },
                    { name: "javaScript", item: false },
                    { name: "Vue.js", item: false },
                ],
            },
            methods: {
                active: function (err) {
                    // 遍历arr数组对象
                    for (var i in this.arr) {
                        // 让active的索引为false
                        this.arr[i].item = false
                    }
                    // 取反
                    this.arr[err].item = !this.arr[err].item
                    console.log(this.arr[err].item);
                }
            }
        })
    </script>
</body>

</html>